﻿using FastIM;
using FreeRedis;
using System.Threading.Channels;

/// <summary>
/// im 核心类实现的配置所需
/// <see cref="https://github.com/2881099/FreeIM"/>
/// </summary>
/// 
public class ImClientOptions
{
    /// <summary>
    /// CSRedis 对象，用于存储数据和发送消息
    /// </summary>
    public RedisClient Redis { get; set; }
    /// <summary>
    /// 负载的服务端
    /// </summary>
    public string[] Servers { get; set; }
    /// <summary>
    /// 发布订阅服务，未设置默认用内置的redis发布订阅服务
    /// </summary>
    public IPubsub Pubsub { get; set; }
    /// <summary>
    /// 服务器发现者。集群服务做负载均衡,选择服务节点。默认用内置的hash求模选择
    /// </summary>
    public IServerDiscover ServerDiscover { get; set; }
    /// <summary>
    /// websocket请求的路径，默认值：/ws
    /// </summary>
    public string PathMatch { get; set; } = "/ws";
    /// <summary>
    /// json序列化的消息MsgTemplate的时候是否忽略null值，如果为true，则消息传输不会传输值为null的属性
    /// </summary>
    public bool IgnoreNullValue { get; set; } = false;
    /// <summary>
    /// token加密解密密钥
    /// </summary>
    public string TokenSecretKey { get; set; } = ".abcdefghijklmnopqrstuvwxyz@1234567890-";
}
/// <summary>
/// 服务端发送消息回调函数事件信息（用于服务器端监听消息发送事件的信息）
/// </summary>
public class ImSendEventArgs : EventArgs
{
    /// <summary>
    /// 发送者的客户端id
    /// </summary>
    public string SenderClientId { get; set; }
    /// <summary>
    /// 发送者登录相关信息（可以传递给接收者的信息）
    /// </summary>
    public ClientMetaData? SenderMetaData { get; set; } = null;
    /// <summary>
    /// 接收者的客户端id
    /// </summary>
    public List<string> ReceiveClientId { get; } = new List<string>();
    /// <summary>
    /// 接收者imServer 服务器节点
    /// </summary>
    public string? Server { get; set; }
    /// <summary>
    /// 消息内容
    /// </summary>
    public object Message { get; set; }
    /// <summary>
    /// 是否回执
    /// </summary>
    public QualityOfServiceLevel Qos { get; set; }
    /// <summary>
    /// 频道
    /// </summary>
    public string? Channel { get; set; }
    /// <summary>
    /// 消息id
    /// </summary>
    public string MsgId { get; set; }
    public int Code { get; set; } = 0;
    public MsgType Type { get; set; } = MsgType.Publish;
    internal ImSendEventArgs()
    {

    }
    internal ImSendEventArgs(string server, string senderClientId, object message, QualityOfServiceLevel Qos = 0, string channel = "", ClientMetaData? senderMetaData = null, string MsgId = null, int Code = 0, MsgType type =MsgType.Publish)
    {
        this.Server = server;
        this.SenderClientId = senderClientId;
        this.Message = message;
        this.Qos = Qos;
        this.Channel = channel;
        this.SenderMetaData = senderMetaData;
        this.MsgId = MsgId;
        this.Code = Code;
        this.Type = type;
    }
}